import 'package:flutter/material.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/common/activity_fun_item.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/dialogs/activity_rule_dialog.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/controllers/activity_controller/ActivityPageController.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/views/activity/activity_new_user.dart';
import 'package:xinxuan/views/activity/activity_old_users.dart';

class ActivityPage extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ActivityPageController>(
      init: ActivityPageController(),
      builder: (controller) {
        // commonPageController.userData.value.isNew = 1;
        return Scaffold(
          backgroundColor: pageBgColor,
          appBar: AppBarUtil(
            title: '星选活动',
            backgroundColor: bgWhiteColor,
            actions: [
              InkWellUtil.shakeProofInkWell(Container(
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                alignment: Alignment.center,
                child: Text(
                  '规则',
                  style: TextStyle(
                    color: mainTextColor,
                    fontSize: 14.sp
                  ),
                ),
              ), () {
                Get.dialog(
                  ActivityRuleDialog(
                    message: controller.activityAcquisitionsVo.value.data!.rules ?? ''
                  )
                );
              })
            ],
          ),
          body: ScrollConfigurationCommon(child: ListView(
            children: [
              commonPageController.userData.value.isNew == 1 ? ActivityNewUser(controller: controller) : ActivityOldUsers(controller: controller),
              Container(
                margin: EdgeInsets.only(top: 12.h),
                padding: EdgeInsets.symmetric(horizontal: 12.w),
                child: Container(
                  padding: EdgeInsets.only(left: 12.w, right: 12.w),
                  decoration: BoxDecoration(
                    color: bgWhiteColor,
                    borderRadius: BorderRadius.circular(5.w)
                  ),
                  child: Column(
                    children: [
                      Container(
                        alignment: Alignment.centerLeft,
                        height: 52.h,
                        child: Text(
                          commonPageController.userData.value.isNew == 1 ? '新人任务' : '活动内容',
                          style: TextStyle(
                            color: textBlackColor,
                            fontSize: 14.sp,
                            fontWeight: FontWeight.bold
                          ),
                        ),
                      ),
                      ActivityFunItem(
                        path: 'assets/icons/icon_authentication.png', 
                        title: '实名认证', 
                        subTitle: '注册用户信息实名认证', 
                        btnStr: controller.activityAcquisitionsVo.value.data!.isIdentified == 0 ? '去认证' : '已认证',
                        isClick: controller.activityAcquisitionsVo.value.data!.isIdentified == 0,
                        onTap: () {
                          controller.activityStep(2);
                        }
                      ),
                      ActivityFunItem(
                        path: 'assets/icons/icon_buy_goods.png', 
                        title: '抢购商品', 
                        subTitle: '抢购商品可获得补贴金', 
                        btnStr: controller.activityAcquisitionsVo.value.data!.isPurchased == 0 ? '去抢购' : '已抢购',
                        isClick: controller.activityAcquisitionsVo.value.data!.isPurchased == 0,
                        onTap: () {
                          controller.activityStep(3);
                        }
                      ),
                      ActivityFunItem(
                        path: 'assets/icons/icon_Invite_new_users.png', 
                        title: '邀请新用户（50元补贴金）', 
                        subTitle: '邀请新用户可获得补贴金', 
                        btnStr: '去邀请',
                        isClick: true,
                        onTap: () {
                          Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.INVITATION_POSTER_PAGE}');
                        }
                      )
                    ],
                  ),
                ),
              )
            ],
          ))
        );
      },
    );
  }
}